/**
 * checksum_util.h
 * 校验和功能
 *
 */
#ifndef __CHECKSUM_UTIL_H_INCLUDED__
#define __CHECKSUM_UTIL_H_INCLUDED__

#include <netinet/ip.h>

#ifdef __cplusplus
extern "C" {
#endif

unsigned short calc_checksum(unsigned short* buffer, int size);

void calc_tcp_checksum(char* raw_buffer);
void calc_udp_checksum(char* raw_buffer);
bool check_tcp_checksum(char* raw_buffer);
bool check_udp_checksum(char* raw_buffer);

/*
 * TCP或者UDP伪首部（pseud header）
 *
 */
typedef struct _psdhdr{
    __u32 source;           //源IP地址
    __u32 dest;             //目的IP地址
    __u8  mbz;              //置空(0)
    __u8  protocol;         //协议类型
    __u16 len;              //传输层包总长度(单位:字节)
}psdhdr;

#ifdef __cplusplus
}
#endif

#endif // __CHECKSUM_UTIL_H_INCLUDED__
